import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
import { MenusService } from './menus.service';
import { CreateMenuDto, UpdateMenuDto, QueryMenusDto } from './dto/menus.dto';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { PermissionGuard } from '../common/guards/permission.guard';
import { RequirePermissions } from '../common/decorators/permission.decorator';

@Controller('menus')
@UseGuards(JwtAuthGuard, PermissionGuard)
export class MenusController {
  constructor(private readonly menusService: MenusService) {}

  @Post()
  @RequirePermissions('menu:create')
  create(@Body() createMenuDto: CreateMenuDto) {
    return this.menusService.create(createMenuDto);
  }

  @Get()
  @RequirePermissions('menu:list')
  findAll(@Query() query: QueryMenusDto) {
    return this.menusService.findAll(query);
  }

  @Get('tree')
  @RequirePermissions('menu:list')
  getMenuTree() {
    return this.menusService.getMenuTree();
  }

  @Get(':id')
  @RequirePermissions('menu:list')
  findOne(@Param('id') id: string) {
    return this.menusService.findById(+id);
  }

  @Patch(':id')
  @RequirePermissions('menu:update')
  update(@Param('id') id: string, @Body() updateMenuDto: UpdateMenuDto) {
    return this.menusService.update(+id, updateMenuDto);
  }

  @Delete(':id')
  @RequirePermissions('menu:delete')
  remove(@Param('id') id: string) {
    return this.menusService.remove(+id);
  }
}